<script>
	import Vue from 'vue';
	import {
		getConfig
	} from '@/apis/request.js';

	export default {
		onLaunch() {
			// 获取小程序更新机制兼容
			const updateManager = uni.getUpdateManager();
			if (updateManager) {
				updateManager.onCheckForUpdate(function(res) {
					// 请求完新版本信息的回调
					if (res.hasUpdate) {
						updateManager.onUpdateReady(function() {
							wx.showModal({
								title: '更新提示',
								content: '新版本已经准备好，是否重启应用？',
								success: function(res) {
									if (res.confirm) {
										// 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
										updateManager.applyUpdate();
									}
								}
							});
						});
						updateManager.onUpdateFailed(function() {
							// 新的版本下载失败
							wx.showModal({
								title: '已经有新版本了哟~',
								content: '新版本已经上线啦~，请您删除当前小程序，重新搜索打开哟~'
							});
						});
					}
				});
			}
			//在入口文件 计算出头部高度
			uni.getSystemInfo({
				success: function(e) {
					// #ifndef MP
					Vue.prototype.StatusBar = e.statusBarHeight;
					if (e.platform == 'android') {
						Vue.prototype.CustomBar = e.statusBarHeight + 50;
					} else {
						Vue.prototype.CustomBar = e.statusBarHeight + 45;
					}
					// #endif

					// #ifdef MP-WEIXIN
					Vue.prototype.StatusBar = e.statusBarHeight;
					let custom = wx.getMenuButtonBoundingClientRect();
					Vue.prototype.Custom = custom;
					Vue.prototype.CustomBar = custom.bottom + custom.top - e.statusBarHeight;
					Vue.prototype.StatusWidth = custom.left;
					// #endif

					// #ifdef MP-ALIPAY
					Vue.prototype.StatusBar = e.statusBarHeight;
					Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
					// #endif
				}
			});
		},
		onShow() {
			getConfig({}).then(res => {
				if (res) {
					Vue.prototype.$shareContent = res.shareContent;
					Vue.prototype.$shareImageUrl = res.shareLogo;
				}
			})
		}
	};
</script>

<style lang="scss">
	@import 'uview-ui/index.scss';

	.view {
		display: flex;
		flex-direction: column;
		background-color: #f2f2f2;
	}

	/*单行*/
	.singline {
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}

	/*两行*/
	.doubleline {
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		overflow: hidden;
		text-overflow: ellipsis;
	}

	.empty-view {
		width: 100%;
		height: 100vh;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: center;
		font-size: 32rpx;
		color: #999;
	}
</style>